<?php
/*********************************************************************\
* This File is a part of BH-PANEL (Breizh-Heberg Panel v2.1)
* Copyright (C) 2008-2009 the BH Developpers : Vincent Giersch <mail@vincordi.fr>, Cyprien Laleau <fanning.fr@gmail.com> and Edwin Cabiten <marmottes44@hotmail.fr>
* See file AUTHORS to get more informations

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
/*********************************************************************/

if(isset($_SESSION['u_nic'])) {
	$title = "Modifier son mot de passe";
	$tplinc = "panel-general-changer-pass";
	$parse = 1;
	$tpl->assign(array(
		'iconesleft' => 1
	));
	include('php/lib/panel_inc.php');
	$error = 0;
	if($_POST['pass_old'] != "") {
		$encodage  = mysql_fetch_array(query("SELECT u_crypt, u_password FROM users_password WHERE u_nic = '".$_SESSION['u_nic']."'"));
		if($encodage['u_crypt'] == 1) {
			$ancien = sha1($_POST['pass_old']);
		}
		else {
			$ancien = md5($_POST['pass_old']);
		}
		if($ancien == $encodage['u_password']) {
			if($_POST['password_new1'] == $_POST['password_new2']) {
				query("UPDATE users_password SET u_crypt = 1, u_password = '".sha1($_POST['password_new1'])."' WHERE u_nic = '".$_SESSION['u_nic']."'");
				$error = 3;
			}
			else {
				$error = 2;
			}
		
		}	
		else {
		$error = 1;
		}
	}	
	$tpl->assign(array(
		"load" => "new Effect.Pulsate(document.getElementById('error'))",
		"error" => $error
	));
}

?>